package me.leiusual.sharing.repository.model

import android.os.CountDownTimer
import androidx.lifecycle.LiveData

/**
 * Create by leiusual on 2018/7/15
 */
class CountDownLiveData(private val count: Long = 3000) : LiveData<Long>() {

  private val countDownTimer = object : CountDownTimer(count + 500, 1000) {

    override fun onTick(millisUntilFinished: Long) {
      value = millisUntilFinished
    }

    override fun onFinish() {
      value = 0
    }
  }

  override fun onActive() {
    countDownTimer.start()
  }

  override fun onInactive() {
    countDownTimer.cancel()
  }
}